<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" isELIgnored="false"%>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="/struts-tags" prefix="s" %>
<%@ taglib uri="http://jsptags.com/tags/navigation/pager" prefix="pg" %>

<style>
	#search_table {text-align:center;border:1px solid #ddd; border-width:0 0 1px 1px;}
	
	#search_table th {background:#CCEEFF;}
	#search_table th,#search_table td {height:22px; border:1px solid #ddd; border-width:1px 1px 0 0;}
</style>


<script type="text/javascript">
<!--
	function deleteStation(stationId){
		window.location.href = "./StationMgr_deleteStation.do?stationId="+stationId;
	}
	
	function onSave(){
		  var errorMsg = "";
			if($("#shortName").val().trim()=="" || $("#fullName").val().trim()=="" || $("#upload").val().trim()==""){
				errorMsg = '<s:text name="dialog.message.tip.needRequiredFields"/>' ;
			}
			if($("#upload").val().trim().indexOf(".png")==-1){
				errorMsg = 'Station Flag just support png File!' ;
			}
			if(errorMsg != ""){
				showErrorTip(errorMsg);
				return false;
			}
			return true;
	}
	
//-->
</script>

<s:include value="./component/tip_box.jsp"></s:include>
<div style="background-color:#F5F5F5;margin-top:1cm;">
	<s:form action="StationMgr_addStation" validate="false" enctype="multipart/form-data" onsubmit="return onSave()">
		<div align="left">
			<s:actionmessage cssStyle="color:#0000FF;"/>
			<s:actionerror cssStyle="color:#F00;"/>
		</div>
		<table width="100%" height="60">
			<tr>
				<td align="right" width="10%" class="label_bold">
				   Short Name<font color="red">*</font>:
				</td>
				<td align="left"  width="10%">
					<s:textfield id="shortName" name="station.shortName" size="15"/>
				</td>
				<td align="right"  width="10%" class="label_bold">
					Full Name<font color="red">*</font>:
				</td>
				<td align="left" width="10%">
					<s:textfield id="fullName" name="station.fullName" size="15"/>
				</td>
				
				<td align="right"  width="10%">
					Flag<font color="red">*</font>:
				</td>
				<td align="left" width="10%">
					<s:file key="upload" id="upload"></s:file>
				</td>
				
				<td align="left" width="20%">
					<s:submit key="action.add" action="StationMgr_addStation" cssClass="btn"/>
					<s:reset key="action.reset" cssClass="btn"/>
				</td>
			</tr>
		</table>
	</s:form>
	
	<table width="100%" id="search_table">
		<thead>
			<tr class="ui-widget-header">
				<th style="width: 20em;">Short Name</th>
				<th style="width: 20em;">Full Name</th>
				<th style="width: 20em;">Flag</th>
				<th style="width: 10em;" colspan="1"><s:text name="action.action"/></th>
			</tr>
		</thead>
		<tbody>
			<c:if test="${empty stationList}">
			   <tr>
				   	<td colspan="3" align="center">
						<font color="red"><s:text name="message.search.nodata"/></font>
				   	</td>
			   </tr>
			</c:if>
			<c:forEach var="each" items="${stationList}">
				<tr>
					<td>${each.shortName}</td>
					<td>${each.fullName}</td>
					<td><img width="20" height="20" src="./StationMgr_showFlagImage.do?flag=${each.flag}"></td>
					<td><input type="button" class="btn" value="Delete" onclick="deleteStation('${each.id}')"></td>
				</tr>
			</c:forEach>
		</tbody>
	</table>
</div>